export const useDevice = () => {
	const event = useRequestEvent();

	// 服务器端设备检测
	if (import.meta.server && event) {
		const userAgent = event.node.req.headers['user-agent'] || '';
		const isMobile = /mobile|android|iphone|ipad|phone/i.test(userAgent.toLowerCase());

		return {
			isMobile: ref(isMobile),
			isDesktop: ref(!isMobile),
			deviceType: ref(isMobile ? 'mobile' : 'desktop'),
		};
	} // 客户端设备检测
	else if (import.meta.client) {
		const userAgent = navigator.userAgent.toLowerCase();
		const isMobile = /mobile|android|iphone|ipad|phone/i.test(userAgent);

		return {
			isMobile: ref(isMobile),
			isDesktop: ref(!isMobile),
			deviceType: ref(isMobile ? 'mobile' : 'desktop'),
		};
	}

	// 默认值
	return {
		isMobile: ref(false),
		isDesktop: ref(true),
		deviceType: ref('desktop'),
	};
};
